package com.ruoyi.web.controller.hospital;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hospital.domain.Health;
import com.ruoyi.hospital.service.IHealthService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 健康百科Controller
 * 
 * @author ruoyi
 * @date 2022-09-07
 */
@RestController
@RequestMapping("/hospital/health")
public class HealthController extends BaseController
{
    @Autowired
    private IHealthService healthService;

    /**
     * 查询健康百科列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:health:list')")
    @GetMapping("/list")
    public TableDataInfo list(Health health)
    {
        startPage();
        List<Health> list = healthService.selectHealthList(health);
        return getDataTable(list);
    }

    /**
     * 导出健康百科列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:health:export')")
    @Log(title = "健康百科", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Health health)
    {
        List<Health> list = healthService.selectHealthList(health);
        ExcelUtil<Health> util = new ExcelUtil<Health>(Health.class);
        util.exportExcel(response, list, "健康百科数据");
    }

    /**
     * 获取健康百科详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:health:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(healthService.selectHealthById(id));
    }

    /**
     * 新增健康百科
     */
    @PreAuthorize("@ss.hasPermi('hospital:health:add')")
    @Log(title = "健康百科", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Health health)
    {
        return toAjax(healthService.insertHealth(health));
    }

    /**
     * 修改健康百科
     */
    @PreAuthorize("@ss.hasPermi('hospital:health:edit')")
    @Log(title = "健康百科", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Health health)
    {
        return toAjax(healthService.updateHealth(health));
    }

    /**
     * 删除健康百科
     */
    @PreAuthorize("@ss.hasPermi('hospital:health:remove')")
    @Log(title = "健康百科", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(healthService.deleteHealthByIds(ids));
    }
}
